import axios, {
  InternalAxiosRequestConfig,
  AxiosResponse,
  AxiosError,
} from "axios";
const service = axios.create({
  baseURL: "/api",
});
//请求拦截器的设置
service.interceptors.request.use(
  (config: InternalAxiosRequestConfig) => {
    config.headers["Content-Type"] = "application/x-www-form-urlencoded";
    config.headers["Content-Type"] = "multipart/form-data";
    const token = localStorage.getItem("token");
    if (token) {
      config.headers["Authori-zation"] = token;
    }
    return config;
  },
  (err: AxiosError) => {
    return Promise.reject(err);
  }
);

//响应拦截器
service.interceptors.response.use(
  (response: AxiosResponse) => {
    return response;
  },
  (err: AxiosError) => {
    return Promise.reject(err);
  }
);
export default service;
